package action.agent;

import org.apache.struts2.ServletActionContext;

import service.interf.IIfwDeviceAuzInfo;
import action.common.MyBaseAction;

import com.opensymphony.xwork2.ModelDriven;

import dao.pojo.IfwDeviceAuzInfo;

public class IfwDeviceAuzInfoAction extends MyBaseAction<IfwDeviceAuzInfo>
		implements ModelDriven<IfwDeviceAuzInfo> {

	private static final long serialVersionUID = 1L;

	private IIfwDeviceAuzInfo iIfwDeviceAuzInfo;
	private int auzTime;
	private int giveTime;
	private String sn2;

	public void setiIfwDeviceAuzInfo(IIfwDeviceAuzInfo iIfwDeviceAuzInfo) {
		this.iIfwDeviceAuzInfo = iIfwDeviceAuzInfo;
	}

	public void setAuzTime(int auzTime) {
		this.auzTime = auzTime;
	}

	public void setGiveTime(int giveTime) {
		this.giveTime = giveTime;
	}

	public void setSn2(String sn2) {
		this.sn2 = sn2;
	}

	public IfwDeviceAuzInfoAction() {
		super(IfwDeviceAuzInfo.class);
	}

	public IfwDeviceAuzInfo getModel() {
		return model;
	}

	/**
	 * 初始化列表
	 */
	public void getlist() {
		String x = "";
		try {
			if (model.getSn() == null || model.getSn().length() == 0) {
				x = iIfwDeviceAuzInfo.findByProperty("IfwDeviceAuzInfo", "*",
						"json", true, null, null, null, null, model.getPage(),
						model.getRows());
			} else {
				x = iIfwDeviceAuzInfo.findByProperty("IfwDeviceAuzInfo", "*",
						"json", true, new String[] { "sn" },
						new Object[] { model.getSn() }, null, null, model
								.getPage(), model.getRows());
			}
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient(ServletActionContext.getResponse(), x);
	}

	/**
	 * 获取主机数
	 */
	public void getHostAllowed() {
		String x = "";
		try {
			x = iIfwDeviceAuzInfo.getHostAllowed(model.getSn());
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 授权
	 */
	public void add() {
		String x = "";
		try {
			x = iIfwDeviceAuzInfo.add(model.getModel(), model.getSn(), auzTime,
					giveTime);
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 授权转移
	 */
	public void change() {
		String x = "";
		try {
			x = iIfwDeviceAuzInfo.change(model.getSn(), sn2);
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 获取到期时间
	 */
	public void getexpiretime() {
		String x = "";
		try {
			x = iIfwDeviceAuzInfo.getExpireTime(model.getSn());
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 设置到期时间
	 */
	public void setexpiretime() {
		String x = "";
		try {
			x = iIfwDeviceAuzInfo.setExpireTime(model.getSn(), model.getExpireTime());
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

}
